package com.example.zhu.mapper;

import com.example.zhu.entity.Withdraw;
import com.example.zhu.vo.WithDrawVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MoneyMapper {

    @Select("select t1.*,t2.money as userMoney from withdraw t1,user_money t2 where t1.openid = t2.openid and t1.status = 0")
    List<WithDrawVO> getWithdraws();

    @Select("select * from withdraw where withdraw_id = #{withdrawId}")
    Withdraw selectById(Integer withdrawId);

    @Update("update withdraw set status = 1 where withdraw_id = #{withdrawId};")
    void updateState(Integer withdrawId);

    @Update("update user_money set money = money-#{withdrawMoney} where openid = #{openid}")
    void updateMoney(String openid, Integer withdrawMoney);

    @Select("select t1.*,t2.money as userMoney from withdraw t1,user_money t2 where t1.openid = t2.openid and t1.withdraw_id=#{id}")
    WithDrawVO getWithdraw(Integer id);

    @Select("select t1.*,t2.money as userMoney from withdraw t1,user_money t2 where t1.openid = t2.openid and t1.phone = #{phone}")
    List<WithDrawVO> getByPhone(String phone);

    @Delete("delete from withdraw where withdraw_id = #{id}")
    void deleteById(Integer id);

    @Delete("delete from user_money where openid = #{openid}")
    void deleteByOpenid(String openid);
}
